package cn.btks.resultintegration.rule.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.catalog.pojo.Catalog;
import cn.btks.resultintegration.rule.pojo.SubstanceParam;
import cn.btks.resultintegration.rule.pojo.SubstanceParamCategory;
import cn.btks.resultintegration.rule.pojo.TwoHighFirstCategory;
import cn.btks.resultintegration.rule.pojo.TwoHighSecondCategory;
import cn.btks.resultintegration.rule.service.SubstanceParamCategoryService;
import cn.btks.resultintegration.rule.service.SubstanceParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/10/15 10:44
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/rule")
@Api(tags = "规则模块")
@Validated
public class SubstanceParamController {

    @Autowired
    SubstanceParamService substanceParamService;

    @Autowired
    SubstanceParamCategoryService substanceParamCategoryService;

    @GetMapping("/substanceParam/findAll")
    @ApiOperation("查询所有物质参数-种类")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<SubstanceParamCategory> list = substanceParamCategoryService.findAll();
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/substanceParam/findById/{id}")
    @ApiOperation("根据ID查询物质参数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findById(@PathVariable("id") Long id) {
        SubstanceParam substanceParam = substanceParamService.findById(id);
        return substanceParam != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), substanceParam) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/substanceParam/findAllByParentId/{id}")
    @ApiOperation("根据种类ID查询物质参数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "种类ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByParentId(@PathVariable("id") Long id) {
        List<SubstanceParam> list = substanceParamService.findAllByParentId(id);
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @PostMapping("/substanceParam/save")
    @ApiOperation(value = "新增物质参数", notes = "新增物质参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState save(@RequestBody SubstanceParam substanceParam) {
        return substanceParamService.save(substanceParam);
    }

    @PutMapping("/substanceParam/update")
    @ApiOperation(value = "更新物质参数", notes = "更新物质参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState update(@RequestBody SubstanceParam substanceParam) {
        return substanceParamService.update(substanceParam);
    }

    @DeleteMapping("/substanceParam/delete/{id}")
    @ApiOperation("根据ID删除物质参数信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "物质参数ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState delete(@PathVariable("id") Long id) {
        return substanceParamService.delete(id);
    }
}
